package l2

import "time"

/**
 * @inventory inventory for l2Network
 * @category l2network
 * @example {
 * "inventory": {
 * "uuid": "f685ff94513542bbb8e814027f8deb13",
 * "name": "l2-basic",
 * "description": "Basic L2 Test",
 * "zoneUuid": "45a2864b6ddf4d2fb9b4c3736a923dcb",
 * "physicalInterface": "eth0",
 * "type": "L2NoVlanNetwork",
 * "createDate": "May 5, 2014 12:58:35 PM",
 * "lastOpDate": "May 5, 2014 12:58:35 PM",
 * "attachedClusterUuids": []
 * }
 * }
 * @since 0.1.0
 */
// @Inventory(mappingVOClass = L2NetworkVO.class)
// @PythonClassInventory
// @ExpandedQueries({
//         @ExpandedQuery(expandedField = "zone", inventoryClass = ZoneInventory.class,
//                 foreignKey = "zoneUuid", expandedInventoryKey = "uuid"),
//         @ExpandedQuery(expandedField = "l3Network", inventoryClass = L3NetworkInventory.class,
//                 foreignKey = "uuid", expandedInventoryKey = "l2NetworkUuid"),
//         @ExpandedQuery(expandedField = "clusterRef", inventoryClass = L2NetworkClusterRefInventory.class,
//                 foreignKey = "uuid", expandedInventoryKey = "l2NetworkUuid", hidden = true),
// })
// @ExpandedQueryAliases({
//         @ExpandedQueryAlias(alias = "cluster", expandedField = "clusterRef.cluster")
// })
type L2NetworkInventory struct {
	Uuid                 string // ResourceVO.Uuid
	Name                 string
	Description          string
	ZoneUuid             string
	PhysicalInterface    string
	Type                 string
	VSwitchType          string
	CreateDate           time.Time
	LastDate             time.Time
	AttachedClusterUuids []string
}

func L2NetworkInventoryValuesOf(vos []*L2NetworkVO) []*L2NetworkInventory {
	invs := make([]*L2NetworkInventory, 0, len(vos))
	for _, vo := range vos {
		invs = append(invs, L2NetworkInventoryValueOf(vo))
	}
	return invs
}

func L2NetworkInventoryValueOf(vo *L2NetworkVO) *L2NetworkInventory {
	i := &L2NetworkInventory{
		Uuid:                 vo.Uuid,
		ZoneUuid:             vo.ZoneUuid,
		Type:                 vo.Type,
		VSwitchType:          vo.VSwitchType,
		Description:          vo.Description,
		Name:                 vo.Name,
		PhysicalInterface:    vo.PhysicalInterface,
		CreateDate:           vo.CreateDate,
		LastDate:             vo.LastOpDate,
		AttachedClusterUuids: make([]string, 0, len(vo.AttachedClusterRefs)),
	}

	for _, ref := range vo.AttachedClusterRefs {
		i.AttachedClusterUuids = append(i.AttachedClusterUuids, ref.ClusterUuid)
	}

	return i
}
